package core.sim;

import stats.*;
import utility.*;
import core.*;
import core.genetic.*;

public class SimpleGroupEvaluation implements Evaluation{


	@Override
	public double[] evaluate(Population pop) {
		int n = pop.size();
		double[] res = new double[n];
								
		Individual[] team = new Individual[ Mode.mode.teamNb];
		
		
		for(int tt = 0;tt<n;tt+= Mode.mode.teamNb) {
			for(int i = 0;i< Mode.mode.teamNb;i++)
				team[i] = pop.get(tt+i);
			double[] points =  Mode.mode.simulation.playSimulation(team);
			for(int i = 0;i< Mode.mode.teamNb;i++)
				res[tt+i] = points[i];
		
		}		
		
//		for(int i = 0;i<n;i++)
//			Statistics.addCost(res[i]);
		
		Statistics.addTotalCosts(res, 1.0);		
		return res;
	}
	
	@Override
	public void executeForMovie(Population pop) {
		Individual[] team = new Individual[Mode.mode.teamNb];			
		int n = team.length;					

		int best = -1;
		double bestValue = 0;
		
		for(int tt = 0;tt<n;tt+= Mode.mode.teamNb) {
			for(int i = 0;i< Mode.mode.teamNb;i++)
				team[i] = pop.get(tt+i);
			double[] points =  Mode.mode.simulation.playSimulation(team);
			double curV = 0;
			for(int i = 0;i< Mode.mode.teamNb;i++)
				curV += points[i];
			if ( best==-1 || bestValue<curV)
			{
				best = tt;
				bestValue = curV;
			}
		}		

		for(int i = 0;i<n;i++)
			team[i] = new Individual(pop.get(i+best));

		Mode.mode.simulation.executeForMovie(team);
	}
	
}
